#!/bin/bash

rootpath=/config

err_exit() {
    echo $1
    exit $2
}

# 符号安装函数
sym_install() {
    local src="$1"
    local dst="$2"
    test -z "$src" && return 1
    test -z "$dst" && return 1
    test -L "$dst" && return 1
    rm "$dst" -rf &> /dev/null
    ln -s "$src" "$dst"
}

# 追加安装函数
append_install() {
    local src="$1"
    local dst="$2"
    test -z "$src" && return 1
    test -z "$dst" && return 1
    grep ". $src" "$dst" &> /dev/null     \
                || echo ". $src" >> "$dst"
}

vim_config() {
    # test -e vim || git clone https://gitee.com/iprintf/vim
    cd $rootpath/vim
    git pull &> /dev/null
    ./linux_install.sh &> /dev/null
}

name="${1-kyo}"
email="${2-iprintf@qq.com}"

echo "正在配置, 请稍等..."
vim_config
append_install $rootpath/bash_config ~/.bashrc
sym_install $rootpath/inputrc ~/.inputrc
sym_install $rootpath/tmux${KYO_TMUX}.conf ~/.tmux.conf
sym_install $rootpath/gitconfig ~/.gitconfig

test -z "$name" || git config --global user.name $name
test -z "$email" || git config --global user.email $email

cd ~

test "x$KYO_TMUX" = "x1" && tmuxArgs=-2

tmux $tmuxArgs new -s kyo \; new-window \; new-window

